/*-*
 * FILENAME  :
 *    $HeadURL$
 *
 * STATUS  :
 *    $Revision$
 *
 *    $Author$
 *    $Date$
 *  
 *    
 * Copyright (c) 2011 Gonalge Ltda. All rights reserved.
 *
 ****************************************************************/

package org.gonalge.sudoku.datos;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.gonalge.sudoku.negocio.Sudoku;
import org.gonalge.sudoku.type.ConfigType;
import org.gonalge.sudoku.util.Configuration;

/**
 * 
 * @author Geremias Gonzalez
 */
public class Guardar {

    public void guardar(Sudoku j) {
        try {

            FileOutputStream f = new FileOutputStream(getUrlFile());
            ObjectOutputStream o = new ObjectOutputStream(f);
            o.writeObject(j);
            o.close();
            f.close();

        } catch (Exception e) {
            System.out.println("Error Guardar");

        }
    }

    public Sudoku recuperar() {
        try {
            FileInputStream f = new FileInputStream(getUrlFile());
            ObjectInputStream o = new ObjectInputStream(f);

            Sudoku ju = (Sudoku) o.readObject();
            o.close();
            f.close();
            return ju;

        } catch (Exception e) {
            System.out.println("Error Recuperar");
            return null;
        }
    }

    public String getUrlFile() {
        return Configuration.getString(ConfigType.URL_DATOS) + Configuration.getString(ConfigType.FILE_DATOS);
    }
}
